#ifndef DIALOGBASE_H
#define DIALOGBASE_H

#include "appsettings.h"

template <class T>
class DialogBase : public QDialog
{
public:
    DialogBase( QWidget * parent, Qt::WindowFlags flags = Qt::Dialog | Qt::WindowCloseButtonHint )
    :   QDialog( parent, flags ),
        m_parent( * parent )
    {
        ui.setupUi( this );
        m_defaultSize = size();
        AppSettings::restoreWidgetState( * this, typeid( T ).name() );
    }

    virtual ~DialogBase()
    {
        AppSettings::saveWidgetState( * this, typeid( T ).name() );
    }

    virtual bool event( QEvent * e )
    {
        if (e->type() == QEvent::NonClientAreaMouseButtonDblClick)
        {
            resize( m_defaultSize );
            e->ignore();
        }

        return QDialog::event( e );
    }

protected:
    T ui;
    QWidget & m_parent;
    QSize m_defaultSize;
};

#endif